<?php

namespace app\api\controller;

use think\Response;
use think\facade\Db;
use think\Request;

class Alliance extends Wap
{
    /**
     * 加盟提交信息
     * @param Request $request
     * @return void
     */
    public function index(Request $request)
    {
        if (request()->isPost()) {
            $post = $request->param();
            $info = Db::name('mini_alliance')->where('mobile', $post['mobile'])->find();
            if ($info) {
                $arr['code'] = 1001;
                $arr['message'] = '您的加盟信息已提交';
                Response::create($arr, 'json')->send();
                exit();
            }
            $data = array(
                'name' => $post['name'],
                'mobile' => $post['mobile'],
                'address' => $post['address'],
                'news' => $post['news'],
                'create_time' => time(),
                'invitation_code' => isset($post['invitation_code']) ? $post['invitation_code'] : '',
                'is_field' => isset($post['is_field']) ? $post['is_field'] : 0,
                'is_budget' => isset($post['is_budget']) ? $post['is_budget'] : 0,
                'is_study' => isset($post['is_study']) ? $post['is_study'] : 0,
                'is_solution' => isset($post['is_solution']) ? $post['is_solution'] : 0,
            );
            if (Db::name('mini_alliance')->insert($data)) {

                $arr['code'] = 200;
                $arr['message'] = '您的加盟信息已提交';
                Response::create($arr, 'json')->send();
                exit();
            }
        }
    }


    /**
     * 加盟信息
     * @param Request $request
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail(Request $request)
    {

        $info = Db::name('mini_user')->where('id', 1)->find();

        $data = array(
            'brief' => $info['brief'],
            'content' => $info['content'],
        );
        $arr['code'] = 200;
        $arr['data'] = $data;
        $arr['message'] = '获取成功';
        Response::create($arr, 'json')->send();
        exit();
    }
}